const {createEditor, createToolbar} = window.wangEditor

const editorConfig = {
    placeholder: 'Type here...',
    onChange(editor) {
        const html = editor.getHtml()
        console.log('editor content', html)
        // 也可以同步到 <textarea>
    },
    MENU_CONF: {
        uploadImage: {
            server: '/admin/upload_img/',
            fieldName: 'your-fileName',
            base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
        }
    }
}

const editor = createEditor({
    selector: '#editor-container',
    html: '<p><br></p>',
    config: editorConfig,
    mode: 'default', // or 'simple'
})

const toolbarConfig = {}

const toolbar = createToolbar({
    editor,
    selector: '#toolbar-container',
    config: toolbarConfig,
    mode: 'default', // or 'simple'
})

$("#blockui-2").click(function (event){
    event.preventDefault();
    let title=$("input[name='title']").val();
    let data_source=$("input[name='data_source']").val();
    let author_name=$("input[name='author_name']").val();
    let category = $("#category-select").val();
    let content = editor.getHtml();
    let csrfmiddlewaretoken = $("input[name='csrfmiddlewaretoken']").val();
    $.ajax('/admin/push_content/',{
        method: 'POST',
        data:{title,author_name,category,content,data_source,csrfmiddlewaretoken},
        success: function (result) {
            if (result['status']) {
                let infor_id = result['data']['infor_id'];
                console.log('发送成功'+infor_id)
                window.location = '/Information_content/' + infor_id
            }else{
                alert(result['message']);
            }
        }

    })


});